package ru.xeden.web.internal;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class DefaultErrorHandler
{
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultErrorHandler.class);

    public void handle(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Exception exception)
    {
        
        try
        {
            servletResponse.sendError(500, exception.getMessage());
            LOGGER.error("", exception);
        }
        catch (IOException e)
        {
            LOGGER.error("Can't render error message, exception for render:" + exception, e);
        }
    }

    public void handleNotFound(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
    {
        try
        {
            servletResponse.sendError(404, "not found");
        }
        catch (IOException e)
        {
            LOGGER.error("handleNotFound", e);
        }
    }
}
